﻿namespace VLCMusic.Tools;

public static class CommonFun
{
    public static string ServiceName
    {
        get
        {
            var name = ConfigurationManager.AppSettings["ServiceName"];
            if (name.IsNull())
            {
                name = "音乐播放器（桌面版）v1.0";
            }
            return name;
        }
    }
    public static int GetRandom(int minNum, int maxNum)
    {
        var seed = BitConverter.ToInt32(Guid.NewGuid().ToByteArray(), 0);
        return new Random(seed).Next(minNum, maxNum);
    }
    public static int GetRandom(int maxNum)
    {
        var seed = BitConverter.ToInt32(Guid.NewGuid().ToByteArray(), 0);
        return new Random(seed).Next(maxNum);
    }
    public static bool IsNull(this string s)
    {
        return string.IsNullOrWhiteSpace(s);
    }
    public static bool NotNull(this string s)
    {
        return !string.IsNullOrWhiteSpace(s);
    }
    public static T ToObject<T>(this string json)
    {
        return JsonConvert.DeserializeObject<T>(json);
    }
    public static void CreateDir(string dir)
    {
        if (dir.Length == 0) return;
        if (!Directory.Exists(dir))
            Directory.CreateDirectory(dir);
    }
}
